from socket import socket, AF_INET, SOCK_DGRAM
# 创建socket
client = socket(AF_INET, SOCK_DGRAM)
# 准备发送数据
data = input("输入要发送的数据：")
# 指定接收方的IP和端口
client.sendto(data.encode("utf-8"), ("localhost", 6666))
# 接收数据,接收数据的地址
recv_data, address = client.recvfrom(1024)
print("接收的数据：",recv_data.decode("utf-8"))
# 关闭socket对象
client.close()